package com.javasm.mb_store_api_final.config.adminLogin.login.service.Impl;


import com.javasm.common.RedisKeys;
import com.javasm.mb_store_api_final.config.adminLogin.login.service.LoginService;
import com.javasm.utils.RandomUtil;

import com.javasm.mb_store_api_final.config.SmsUtil;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @Author: xmm
 * <p>
 * &#064;@Description:
 * <p>
 * &#064;@Date 2024/7/26 下午4:47
 */
@Service("loginService")
public class LoginServiceImpl implements LoginService {

    @Resource
    SmsUtil smsUtil;

    @Resource
    RedisTemplate<String,String> redisTemplate;


    @Override
    @Async
    public void sendCode(String phone) {
        String code = RandomUtil.getCode(4);
        smsUtil.sendSms(phone,code);
        String key = String.format(RedisKeys.UserCodePhone,phone);
        redisTemplate.opsForValue().set(key,code,15, TimeUnit.DAYS);
    }
}
